<template>
  <div class="werewolf-room">
    <!-- 顶部房间信息栏 -->
    <div class="room-header">
      <div class="room-info">
        <div class="room-avatar">🐺</div>
        <div class="room-details">
          <div class="room-title">
            <span class="game-icon">🌙</span>
            <span>狼人杀 - 第{{ currentRound }}轮发言</span>
          </div>
          <div class="room-status">
            <span class="status-item phase">
              <span class="status-dot"></span>
              {{ currentPhase }}
            </span>
            <span class="status-item">👥 {{ alivePlayers.length }}/{{ totalPlayers }}人存活</span>
            <span class="status-item">⏰ {{ formatTime(remainingTime) }}</span>
          </div>
        </div>
      </div>
      <div class="room-actions">
        <button class="action-btn secondary" @click="handleSettings">
          <span class="icon">⚙️</span>
          <span>设置</span>
        </button>
        <button class="action-btn secondary" @click="handleRules">
          <span class="icon">📖</span>
          <span>规则</span>
        </button>
        <button class="action-btn primary" @click="handleSkipSpeech" :disabled="!canSkip">
          <span class="icon">⏭️</span>
          <span>跳过发言</span>
        </button>
      </div>
    </div>

    <!-- 主内容区域 -->
    <div class="main-content">
      <!-- 左侧发言区域 -->
      <div class="speech-area">
        <!-- 当前发言者舞台 -->
        <div class="current-speaker-stage">
          <!-- 左侧剧本区域 -->
          <div class="script-section">
            <div class="script-header">
              <span class="script-icon">📜</span>
              <span class="script-title">{{ currentScript.title }}</span>
            </div>
            <div class="script-content">
              <div class="script-description">
                {{ currentScript.description }}
              </div>
              <div class="script-roles">
                <div class="roles-title">角色配置：</div>
                <div class="roles-list">
                  <div
                    v-for="role in currentScript.roles"
                    :key="role.type"
                    class="role-item"
                  >
                    <span class="role-icon">{{ getRoleIcon(role.type) }}</span>
                    <span class="role-name">{{ getRoleName(role.type) }}</span>
                    <span class="role-count">×{{ role.count }}</span>
                  </div>
                </div>
              </div>
              <div class="script-rules">
                <div class="rules-title">特殊规则：</div>
                <ul class="rules-list">
                  <li v-for="rule in currentScript.specialRules" :key="rule">
                    {{ rule }}
                  </li>
                </ul>
              </div>
            </div>
          </div>

          <!-- 右侧发言人区域 -->
          <div class="speaker-section">
            <div class="speaker-info">
              <div class="speaker-avatar" :class="currentSpeaker.role">
                <span class="avatar-text">{{ currentSpeaker.seat }}</span>
                <div class="role-indicator" v-if="showRoles">{{ getRoleIcon(currentSpeaker.role) }}</div>
              </div>
              <div class="speaker-details">
                <div class="speaker-name">{{ currentSpeaker.name }}</div>
                <div class="speaker-seat">{{ currentSpeaker.seat }}号位</div>
                <div class="speaker-role" v-if="showRoles">{{ getRoleName(currentSpeaker.role) }}</div>
                <div class="speech-status">正在发言中...</div>
              </div>
            </div>

            <!-- 发言计时器 -->
            <div class="speech-timer">
              <div class="timer-circle">
                <svg class="timer-svg" viewBox="0 0 100 100">
                  <circle
                    cx="50"
                    cy="50"
                    r="45"
                    fill="none"
                    stroke="rgba(255, 255, 255, 0.2)"
                    stroke-width="4"
                  />
                  <circle
                    cx="50"
                    cy="50"
                    r="45"
                    fill="none"
                    stroke="#fbbf24"
                    stroke-width="4"
                    stroke-linecap="round"
                    :stroke-dasharray="circumference"
                    :stroke-dashoffset="strokeDashoffset"
                    class="timer-progress"
                  />
                </svg>
                <div class="timer-text">{{ remainingTime }}s</div>
              </div>
            </div>
          </div>
        </div>

        <!-- 操作按钮 -->
        <div class="action-buttons">
          <button
            class="action-button vote-btn"
            @click="handleVote"
            :disabled="currentPhase !== '投票阶段'"
          >
            <span class="btn-icon">🗳️</span>
            <span>投票</span>
          </button>
          <button
            class="action-button skill-btn"
            @click="handleUseSkill"
            :disabled="!canUseSkill"
          >
            <span class="btn-icon">✨</span>
            <span>使用技能</span>
          </button>
          <button
            class="action-button next-btn"
            @click="handleNextSpeaker"
            :disabled="!isCurrentPlayer"
          >
            <span class="btn-icon">➡️</span>
            <span>结束发言</span>
          </button>
        </div>
      </div>

      <!-- 右侧边栏 -->
      <div class="sidebar">
        <!-- 玩家列表 -->
        <div class="players-panel">
          <div class="panel-header">
            <span class="panel-title">
              <span class="icon">👥</span>
              <span>玩家列表</span>
            </span>
            <span class="player-count">{{ alivePlayers.length }}/{{ totalPlayers }}</span>
          </div>
          <div class="players-grid">
            <div
              v-for="player in allPlayers"
              :key="player.id"
              :class="['player-card', {
                'current': player.id === currentSpeaker.id,
                'dead': !player.alive,
                'voted': player.voted
              }]"
            >
              <div class="player-avatar" :class="player.role">
                <span class="seat-number">{{ player.seat }}</span>
                <div class="role-badge" v-if="showRoles">{{ getRoleIcon(player.role) }}</div>
                <div class="status-overlay" v-if="!player.alive">💀</div>
                <div class="speaking-indicator" v-if="player.id === currentSpeaker.id">🎤</div>
              </div>
              <div class="player-name">{{ player.name }}</div>
              <div class="player-status">
                <span v-if="!player.alive" class="status dead">已出局</span>
                <span v-else-if="player.voted" class="status voted">已投票</span>
                <span v-else-if="player.id === currentSpeaker.id" class="status speaking">发言中</span>
                <span v-else class="status alive">存活</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 聊天室 -->
        <div class="chat-panel">
          <div class="panel-header">
            <span class="panel-title">
              <span class="icon">💬</span>
              <span>游戏记录</span>
            </span>
          </div>
          <div class="chat-messages" ref="chatContainer">
            <div
              v-for="message in gameMessages"
              :key="message.id"
              :class="['game-message', message.type]"
            >
              <div class="message-time">{{ message.time }}</div>
              <div class="message-content">
                <span v-if="message.player" class="message-player">{{ message.player }}：</span>
                <span class="message-text">{{ message.content }}</span>
              </div>
            </div>
          </div>
          <div class="chat-input" v-if="canChat">
            <input
              v-model="newMessage"
              type="text"
              placeholder="输入消息..."
              @keyup.enter="sendMessage"
              class="message-input"
            >
            <button class="send-btn" @click="sendMessage">发送</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed, nextTick, watch, onMounted, onUnmounted } from 'vue'

// 类型定义
interface Player {
  id: string
  name: string
  seat: number
  role: 'werewolf' | 'villager' | 'seer' | 'witch' | 'hunter' | 'guard'
  alive: boolean
  voted: boolean
}

interface GameMessage {
  id: string
  type: 'system' | 'speech' | 'vote' | 'skill'
  player?: string
  content: string
  time: string
}

interface ScriptRole {
  type: string
  count: number
}

interface Script {
  title: string
  description: string
  roles: ScriptRole[]
  specialRules: string[]
}

// 响应式数据
const currentRound = ref(1)
const currentPhase = ref('白天发言阶段')
const remainingTime = ref(60)
const currentSpeakerIndex = ref(0)
const showRoles = ref(false)
const canSkip = ref(false)
const canUseSkill = ref(false)
const canChat = ref(true)
const isCurrentPlayer = ref(true)

const totalPlayers = ref(12)
const speechTimeLimit = ref(60)

// 剧本数据
const currentScript = ref<Script>({
  title: '经典12人局',
  description: '经典的狼人杀配置，适合新手和老玩家。包含预言家、女巫、猎人、守卫等经典角色，平衡性良好。',
  roles: [
    { type: 'werewolf', count: 4 },
    { type: 'villager', count: 4 },
    { type: 'seer', count: 1 },
    { type: 'witch', count: 1 },
    { type: 'hunter', count: 1 },
    { type: 'guard', count: 1 }
  ],
  specialRules: [
    '女巫不能自救',
    '守卫不能连续两晚守同一人',
    '猎人被女巫毒死不能开枪',
    '首夜不能刀守卫保护的人'
  ]
})

// 玩家数据
const allPlayers = ref<Player[]>([
  { id: '1', name: '甜心', seat: 1, role: 'seer', alive: true, voted: false },
  { id: '2', name: '小美', seat: 2, role: 'werewolf', alive: true, voted: false },
  { id: '3', name: '阿强', seat: 3, role: 'villager', alive: true, voted: true },
  { id: '4', name: '露露', seat: 4, role: 'witch', alive: false, voted: false },
  { id: '5', name: '小明', seat: 5, role: 'villager', alive: true, voted: false },
  { id: '6', name: '大王', seat: 6, role: 'hunter', alive: true, voted: false },
  { id: '7', name: '小李', seat: 7, role: 'guard', alive: true, voted: false },
  { id: '8', name: '小张', seat: 8, role: 'werewolf', alive: false, voted: false },
  { id: '9', name: '小王', seat: 9, role: 'villager', alive: true, voted: false },
  { id: '10', name: '小赵', seat: 10, role: 'villager', alive: true, voted: false },
  { id: '11', name: '小刘', seat: 11, role: 'werewolf', alive: true, voted: false },
  { id: '12', name: '小陈', seat: 12, role: 'villager', alive: true, voted: false }
])

const gameMessages = ref<GameMessage[]>([
  {
    id: '1',
    type: 'system',
    content: '游戏开始，进入白天发言阶段',
    time: '14:30'
  },
  {
    id: '2',
    type: 'speech',
    player: '甜心',
    content: '我是预言家，昨晚验了2号，是狼人！',
    time: '14:31'
  },
  {
    id: '3',
    type: 'speech',
    player: '小美',
    content: '我不是狼人，甜心在污蔑我！',
    time: '14:32'
  },
  {
    id: '4',
    type: 'vote',
    content: '阿强投票给了小美',
    time: '14:33'
  }
])

// 计算属性
const alivePlayers = computed(() => allPlayers.value.filter(p => p.alive))

const speechOrder = computed(() => {
  return alivePlayers.value.sort((a, b) => a.seat - b.seat)
})

const currentSpeaker = computed(() => {
  return speechOrder.value[currentSpeakerIndex.value] || speechOrder.value[0]
})

const circumference = computed(() => 2 * Math.PI * 45)

const strokeDashoffset = computed(() => {
  const progress = remainingTime.value / speechTimeLimit.value
  return circumference.value * (1 - progress)
})

const newMessage = ref('')
const chatContainer = ref<HTMLElement>()

// 定时器
let timer: number | null = null

// 方法
const formatTime = (seconds: number) => {
  const mins = Math.floor(seconds / 60)
  const secs = seconds % 60
  return mins > 0 ? `${mins}:${secs.toString().padStart(2, '0')}` : `${secs}`
}

const getRoleIcon = (role: string) => {
  const roleIcons = {
    werewolf: '🐺',
    villager: '👨‍🌾',
    seer: '🔮',
    witch: '🧙‍♀️',
    hunter: '🏹',
    guard: '🛡️'
  }
  return roleIcons[role as keyof typeof roleIcons] || '❓'
}

const getRoleName = (role: string) => {
  const roleNames = {
    werewolf: '狼人',
    villager: '村民',
    seer: '预言家',
    witch: '女巫',
    hunter: '猎人',
    guard: '守卫'
  }
  return roleNames[role as keyof typeof roleNames] || '未知'
}

const startTimer = () => {
  if (timer) clearInterval(timer)
  remainingTime.value = speechTimeLimit.value

  timer = setInterval(() => {
    remainingTime.value--
    if (remainingTime.value <= 0) {
      handleNextSpeaker()
    }
  }, 1000)
}

const handleNextSpeaker = () => {
  if (timer) clearInterval(timer)

  // 添加发言记录
  const message: GameMessage = {
    id: Date.now().toString(),
    type: 'speech',
    player: currentSpeaker.value.name,
    content: '发言结束',
    time: new Date().toLocaleTimeString('zh-CN', {
      hour: '2-digit',
      minute: '2-digit'
    })
  }
  gameMessages.value.push(message)

  // 切换到下一个发言者
  currentSpeakerIndex.value++
  if (currentSpeakerIndex.value >= speechOrder.value.length) {
    // 所有人发言完毕，进入投票阶段
    currentPhase.value = '投票阶段'
    currentSpeakerIndex.value = 0
  } else {
    startTimer()
  }
}

const handleVote = () => {
  console.log('投票')
}

const handleUseSkill = () => {
  console.log('使用技能')
}

const handleSkipSpeech = () => {
  handleNextSpeaker()
}

const handleSettings = () => {
  console.log('设置')
}

const handleRules = () => {
  console.log('规则')
}

const sendMessage = () => {
  if (newMessage.value.trim()) {
    const message: GameMessage = {
      id: Date.now().toString(),
      type: 'speech',
      player: '我',
      content: newMessage.value.trim(),
      time: new Date().toLocaleTimeString('zh-CN', {
        hour: '2-digit',
        minute: '2-digit'
      })
    }
    gameMessages.value.push(message)
    newMessage.value = ''
  }
}

// 生命周期
onMounted(() => {
  startTimer()
})

onUnmounted(() => {
  if (timer) clearInterval(timer)
})

// 监听聊天消息变化，自动滚动
watch(() => gameMessages.value.length, () => {
  nextTick(() => {
    if (chatContainer.value) {
      chatContainer.value.scrollTop = chatContainer.value.scrollHeight
    }
  })
})
</script>

<style scoped>
.werewolf-room {
  min-height: 100vh;
  background: linear-gradient(135deg, #2c1810 0%, #1a1a2e 50%, #16213e 100%);
  padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #e2e8f0;
}

/* 顶部房间信息栏 */
.room-header {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.room-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.room-avatar {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #8b5a2b 0%, #d4af37 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(139, 90, 43, 0.4);
}

.room-title {
  font-size: 16px;
  font-weight: 600;
  color: #f1f5f9;
  margin-bottom: 4px;
}

.room-status {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #94a3b8;
}

.status-item.phase {
  color: #fbbf24;
  font-weight: 500;
}

.status-dot {
  width: 6px;
  height: 6px;
  background: #fbbf24;
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}

.room-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.action-btn.primary {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
  color: white;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 主内容区域 */
.main-content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
}

/* 左侧发言区域 */
.speech-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.current-speaker-stage {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  gap: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* 左侧剧本区域 */
.script-section {
  flex: 1;
  min-width: 0;
}

.script-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.script-icon {
  font-size: 18px;
}

.script-title {
  font-size: 18px;
  font-weight: 600;
  color: #fbbf24;
}

.script-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.script-description {
  font-size: 14px;
  color: #cbd5e1;
  line-height: 1.5;
}

.script-roles {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
}

.roles-title {
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
  margin-bottom: 8px;
}

.roles-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.role-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #cbd5e1;
}

.role-icon {
  font-size: 14px;
}

.role-name {
  flex: 1;
}

.role-count {
  color: #fbbf24;
  font-weight: 500;
}

.script-rules {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
}

.rules-title {
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
  margin-bottom: 8px;
}

.rules-list {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.4;
}

.rules-list li {
  margin-bottom: 4px;
}

/* 右侧发言人区域 */
.speaker-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 200px;
}

.speaker-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.speaker-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  color: white;
  position: relative;
  border: 3px solid rgba(255, 255, 255, 0.3);
}

.speaker-avatar.werewolf {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}

.speaker-avatar.villager {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.speaker-avatar.seer {
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
}

.speaker-avatar.witch {
  background: linear-gradient(135deg, #db2777 0%, #be185d 100%);
}

.speaker-avatar.hunter {
  background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
}

.speaker-avatar.guard {
  background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%);
}

.role-indicator {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.speaker-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.speaker-name {
  font-size: 18px;
  font-weight: 600;
  color: #f1f5f9;
}

.speaker-seat {
  font-size: 14px;
  color: #94a3b8;
}

.speaker-role {
  font-size: 14px;
  color: #fbbf24;
}

.speech-status {
  font-size: 12px;
  color: #94a3b8;
}

.speech-timer {
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-circle {
  position: relative;
  width: 80px;
  height: 80px;
}

.timer-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-progress {
  transition: stroke-dashoffset 1s linear;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
  font-weight: 600;
  color: white;
}

/* 操作按钮 */
.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.vote-btn {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
  color: white;
}

.skill-btn {
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
  color: white;
}

.next-btn {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: white;
}

.action-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 右侧边栏 */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.players-panel,
.chat-panel {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #f1f5f9;
}

.player-count {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
}

/* 玩家网格 */
.players-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.player-card.current {
  background: rgba(251, 191, 36, 0.2);
  border-color: rgba(251, 191, 36, 0.3);
}

.player-card.dead {
  opacity: 0.5;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: white;
  position: relative;
  margin-bottom: 4px;
}

.seat-number {
  position: relative;
  z-index: 2;
}

.role-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
}

.status-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.speaking-indicator {
  position: absolute;
  top: -6px;
  left: -6px;
  font-size: 12px;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.player-name {
  font-size: 10px;
  font-weight: 500;
  color: #f1f5f9;
  text-align: center;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.player-status {
  font-size: 8px;
  text-align: center;
}

.status.dead { color: #ef4444; }
.status.voted { color: #10b981; }
.status.speaking { color: #fbbf24; }
.status.alive { color: #94a3b8; }

/* 聊天区域 */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 12px;
  padding-right: 4px;
}

.chat-messages::-webkit-scrollbar {
  width: 3px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.game-message {
  margin-bottom: 8px;
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.game-message.system {
  background: rgba(251, 191, 36, 0.2);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.game-message.speech {
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.game-message.vote {
  background: rgba(220, 38, 38, 0.2);
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.game-message.skill {
  background: rgba(124, 58, 237, 0.2);
  border: 1px solid rgba(124, 58, 237, 0.3);
}

.message-time {
  font-size: 10px;
  color: #94a3b8;
  margin-bottom: 2px;
}

.message-player {
  font-weight: 600;
  color: #fbbf24;
}

.message-text {
  color: #e2e8f0;
}

.chat-input {
  display: flex;
  gap: 8px;
}

.message-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  font-size: 12px;
  outline: none;
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.message-input::placeholder {
  color: #94a3b8;
}

.send-btn {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: -1;
  }

  .players-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .current-speaker-stage {
    flex-direction: column;
    gap: 16px;
  }

  .speaker-section {
    min-width: auto;
  }
}

@media (max-width: 768px) {
  .werewolf-room {
    padding: 12px;
  }

  .room-header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }

  .players-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .action-buttons {
    flex-direction: column;
  }

  .roles-list {
    grid-template-columns: 1fr;
  }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
</style>
